*******************************************************************************************************************************
*********** PILOT STUDY - TESTING THE SUBORDINATE MALE TARGET HYPOTHESIS ON EVALUATIONS OF DANISH POLITICAL CANDIDATES ********
*******************************************************************************************************************************


***************************************************** Recodings ***************************************************************

*** Target politician Sex
generate candidate_sex = .
replace candidate_sex = 0 if splitgroup == 1
replace candidate_sex = 0 if splitgroup == 3
replace candidate_sex = 1 if splitgroup == 2
replace candidate_sex = 1 if splitgroup == 4
lab def cand_sexLB 0 "Male" 1 "Female"
lab val candidate_sex cand_sexLB

*** Target Politician Ethnicity
generate candidate_ethnicity = .
replace candidate_ethnicity = 0 if splitgroup == 1
replace candidate_ethnicity = 0 if splitgroup == 2
replace candidate_ethnicity = 1 if splitgroup == 3
replace candidate_ethnicity = 1 if splitgroup == 4
lab def cand_ethLB 0 "Danish" 1 "Non-Danish"
lab val candidate_ethnicity cand_ethLB

*** Social Dominance Orientation
correlate q3_1 q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8
recode q3_1 q3_2 q3_3 q3_4 (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7=7) (else=.)
recode q3_3 q3_4 q3_7 q3_8 (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1) (else=.)
alpha q3_1 q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8

egen sdo = rowmean(q3_1 q3_2 q3_3 q3_4 q3_5 q3_6 q3_7 q3_8)
generate SDO = (sdo-1)/6
summ SDO


*** Political ideology (left-right self-placement)
generate ideology = q2/10
summ ideology


*** Rightwing Authoritarianism
correlate q4_1 q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8
recode q4_1 q4_3 q4_4 q4_5 (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7=7) (else=.)
recode q4_2 q4_6 q4_7 q4_8 (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1) (else=.)
alpha q4_1 q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8

egen rwa = rowmean(q4_1 q4_2 q4_3 q4_4 q4_5 q4_6 q4_7 q4_8)
generate RWA = (rwa-1)/6
summ RWA


*** Party preference
recode q1 (1 2 4 9 16 18 20=0) (3 5 6 7 8 17 19=1) (else=.), gen(rightwing)
tab rightwing



*** Dependent variable: Evaluation of assigned fictitious politician
generate DV = q7/10
summ DV


**** Control variables
* Gender
recode gender (1=1 "female") (2=0 "male"), generate(sex)
tab sex

* Age
clonevar age = profile_age2
tab age

* Education
recode profile_education (1=1) (2 3 =2) (4=3) (5=4) (6=5) (7 8=6), gen(education)
tab education

* Geographical region
tab region

* Personal income
recode personal_income (12 13=.), generate(income_personal)
tab income_personal

* Household income
recode household_income (12 13=.), generate(income_household)
tab income_household



***************************************************** Balance Test ***********************************************************
** Tests balance across experimental conditions for respondents' sex
tab splitgroup sex, row chi

** Tests balance across experimental conditions for respondents' age
tab splitgroup age, row chi

** Tests balance across experimental conditions for respondents' education
tab splitgroup education, row chi

** Tests balance across experimental conditions for respondents' regional belonging
tab splitgroup region, row chi


** Tests if averages on ideology variables varies across experimental conditions
reg SDO i.splitgroup
testparm i.splitgroup

reg RWA i.splitgroup
testparm i.splitgroup

reg ideology i.splitgroup
testparm i.splitgroup

logit rightwing i.splitgroup
testparm i.splitgroup


******************************************************************************************************************************
***************************************************** Analysis ***************************************************************
******************************************************************************************************************************

*------------------------------------------ PRE-REGISTERED HYPOTHESES--------------------------------------------------------*

*** Full models for results of analyses of H1-H5 are reported in Online Appendiks A.3

*** H1) Do male candidates receive more positive evaluations than female candidates?
reg DV i.candidate_sex, robust
margins, at(candidate_sex=(0 1))


*** H2) Do Danish candidates receive more positive evaluations than non-Danish candidates?
reg DV i.candidate_ethnicity, robust
margins, at(candidate_ethnicity=(0 1))


*** H3) Do candidate sex and ethnicity interact such that the negative effect of being non-Danish is more pronounced for non-Danish male candidates compared to non-Danish female candidates?
reg DV i.candidate_sex##i.candidate_ethnicity, robust


** Plots average candidate evaluations across assigned conditions for candidate gender and ethnicity (Figur 1 in article)
margins, at(candidate_sex=(0 1) candidate_ethnicity=(0 1))
marginsplot, recastci(rcap) ciopts(lpattern(dash)) recast(bar) yline(0) yscale(range(0 (.2) 1)) ylabel(0 (.2) 1 ,nogrid) yline(0) by(candidate_sex) name(Figure1_maineff, replace)


*** H4) Does respondent sex moderate the two-way interaction between candidate sex and candidate ethnicity? (such that the two-way interaction is stronger for male respondents?)
reg DV i.candidate_sex##i.candidate_ethnicity##i.sex i.region c.age i.education, robust


*** H5) Does respondent SDO moderate the two-way interaction between candidate sex and candidate ethnicity?
reg DV i.candidate_sex##i.candidate_ethnicity##c.SDO i.region i.sex c.age i.education, robust

** Plots results in figure split by candiadte gender (Figur 2 in article)
margins, at(SDO=(0 (.1) 1) candidate_sex=(0 1) candidate_ethnicity=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) yscale(range(0 1)) ylabel(0 (.2) 1 ,nogrid) by(candidate_sex) ///
xtitle("Social Dominance Orientation") ytitle("Kandidatevaluering") title("") name(H5_pred_val, replace)


** Creates table with models for the five hypotheses
quietly: reg DV i.candidate_sex, robust
eststo model1

quietly: reg DV i.candidate_ethnicity, robust
eststo model2

quietly: reg DV i.candidate_sex##i.candidate_ethnicity, robust
eststo model3 

quietly: reg DV i.candidate_sex##i.candidate_ethnicity##i.sex i.region c.age i.education, robust
eststo model4

quietly: reg DV i.candidate_sex##i.candidate_ethnicity##c.SDO i.region i.sex c.age i.education, robust
eststo model5

etable, estimates(model1 model2 model3 model4 model5) mstat(N) mstat(r2_a) showstars showstarsnote export(table1.docx)


** Online Appendiks A.4: Creates marginal effect plots for analyses displayed in Figure 2 (i.e., testing H5)
reg DV i.candidate_sex##i.candidate_ethnicity##c.SDO i.region i.sex c.age i.education, robust
margins, dydx(candidate_ethnicity) at(SDO=(0 (.1) 1) candidate_sex=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) yscale(range(-.1 .1)) ylabel(-.4 (.1) .2 ,nogrid) by(candidate_sex) ///
xtitle("Social Dominance Orientation") ytitle("Kandidatevaluering") title("") name(H5_marg_eff, replace)


*** Test of four-way interaction between candidate sex, candidate ethnicity, respondent SDO and respondent sex as stated in the pre-registration (reported in footnote 6)
reg DV i.candidate_sex##i.candidate_ethnicity##c.SDO##i.gender i.region i.gender c.age i.education, robust


*------------------------------------------ EXPLORATORY ANALYSES--------------------------------------------------------*
***** Tests two-way interactions between candidate ethnicity and each of the four different ideological variables (SDO, RWA, self-identified ideology and dichotomous party choice)

*** Full models for the following four models are reported in Online Appendiks A.5

* SDO
reg DV i.candidate_sex i.candidate_ethnicity##c.SDO i.region i.gender c.age i.education, robust
margins, dydx(candidate_ethnicity) at(SDO=(0 (.1) 1))
margins, at(SDO=(0 (.1) 1) candidate_ethnicity=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) yscale(range(0 1)) ylabel(0 (.2) 1 ,nogrid) ///
xtitle("Social Dominance Orientation") ytitle("Kandidatevaluering") title("") name(Figur3_SDO, replace)

* RWA
reg DV i.candidate_sex i.candidate_ethnicity##c.RWA i.region i.gender c.age i.education, robust
margins, dydx(candidate_ethnicity) at(RWA=(0 (.1) 1))
margins, at(RWA=(0 (.1) 1) candidate_ethnicity=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) yscale(range(0 1)) ylabel(0 (.2) 1 ,nogrid) ///
xtitle("Rightwing Authoritarianism") ytitle("Kandidatevaluering") title("") name(Figur3_RWA, replace)

* Self-identified ideology
reg DV i.candidate_sex i.candidate_ethnicity##c.ideology i.region i.gender c.age i.education, robust
margins, dydx(candidate_ethnicity) at(ideology=(0 (.1) 1))
margins, at(ideology=(0 (.1) 1) candidate_ethnicity=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) yscale(range(0 1)) ylabel(0 (.2) 1 ,nogrid) ///
xtitle("Selvidentificeret ideologi") ytitle("Kandidatevaluering") title("") name(Figur3_Ideologi, replace)

* Party choice (dichotomized)
reg DV i.candidate_sex i.candidate_ethnicity##i.rightwing i.region i.gender c.age i.education, robust
margins, dydx(candidate_ethnicity) at(rightwing=(0 1))
margins, at(rightwing=(0 1) candidate_ethnicity=(0 1))
marginsplot, recastci(rcap) ciopts(lpattern(dash)) recast(scatter) yline(0) yscale(range(0 1)) ylabel(0 (.2) 1 ,nogrid) ///
xtitle("Partivalg") ytitle("Kandidatevaluering") title("") name(Figur3_parti, replace)

* Creates common figure across the four ideology vriables (Figur 3 in article)
graph combine Figur3_SDO Figur3_RWA Figur3_Ideologi Figur3_parti 


*** Online Appendiks A.6: Creates marginal effect plots for analyses displayed in Figure 3 (two-way interactions between candidate ethnicity and ideological variables) and further tests if interactions can be assumed to be linear.
* SDO
interflex DV candidate_ethnicity SDO region gender age education

* RWA
interflex DV candidate_ethnicity RWA region gender age education

* Self-identified ideology
interflex DV candidate_ethnicity ideology region gender age education



***** Tests two-way interactions between candidate sex and each of the four different ideological variables (SDO, RWA, self-identified ideology and dichotomous party choice)
* SDO
reg DV i.candidate_ethnicity i.candidate_sex##c.SDO i.region i.gender c.age i.education, robust

* RWA
reg DV i.candidate_ethnicity i.candidate_sex##c.RWA i.region i.gender c.age i.education, robust

* Selvidetificeret ideologi
reg DV i.candidate_ethnicity i.candidate_sex##c.ideology i.region i.gender c.age i.education, robust

* Partivalg
reg DV i.candidate_ethnicity i.candidate_sex##i.rightwing i.region i.gender c.age i.education, robust


***** Tests two alternative modelleing strategies for exploratory tests of two-way interactions between candidate ethnicity and each of the four different ideological variables (SDO, RWA, self-identified ideology and dichotomous party choice)
*** Without any control variables
* SDO
reg DV i.candidate_sex i.candidate_ethnicity##c.SDO, robust

* RWA
reg DV i.candidate_sex i.candidate_ethnicity##c.RWA, robust

* Selvidetificeret ideologi
reg DV i.candidate_sex i.candidate_ethnicity##c.ideology, robust

* Partivalg
reg DV i.candidate_sex i.candidate_ethnicity##i.rightwing, robust


*** Including respondents' family income as control variable
* SDO
reg DV i.candidate_sex i.candidate_ethnicity##c.SDO i.region i.gender c.age i.education c.income_household, robust
* RWA
reg DV i.candidate_sex i.candidate_ethnicity##c.RWA i.region i.gender c.age i.education c.income_household, robust

* Selvidetificeret ideologi
reg DV i.candidate_sex i.candidate_ethnicity##c.ideology i.region i.gender c.age i.education c.income_household, robust

* Partivalg
reg DV i.candidate_sex i.candidate_ethnicity##i.rightwing i.region i.gender c.age i.education c.income_household, robust


